package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectRepairDetailListener;
import com.longxi.tianjintianbao.model.RepairList;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class RepairListViewBinder extends ItemViewBinder<RepairList, RepairListViewBinder.ViewHolder> {

    SelectRepairDetailListener listener;

    public RepairListViewBinder(SelectRepairDetailListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_repair_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull RepairList repairList) {
        holder.mTvTime.setText(repairList.getBilldate());
        holder.mTvStatus.setText(repairList.getState());
        holder.mTvName.setText(repairList.getContacts());
        holder.mTvAddress.setText(repairList.getAddress());
        holder.mTvRepairArea.setText("维修区域:" + repairList.getRegion() + " 类型:" + repairList.getRepairtype() + " 类别:" + repairList.getRepaircategory());

        holder.mTvRepairContent.setText(repairList.getContent());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(repairList.getBillid());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvTime;
        TextView mTvStatus;
        TextView mTvName;
        TextView mTvAddress;
        TextView mTvRepairArea;
        TextView mTvRepairContent;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvTime = itemView.findViewById(R.id.tvTime);
            mTvStatus = itemView.findViewById(R.id.tvStatus);
            mTvName = itemView.findViewById(R.id.tvName);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
            mTvRepairArea = itemView.findViewById(R.id.tvRepairArea);
            mTvRepairContent = itemView.findViewById(R.id.tvRepairContent);
        }
    }
}
